package com.example.springboot_admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot_admin.pojo.Posts;
import com.example.springboot_admin.pojo.Users;
import com.example.springboot_admin.service.IPostsService;
import com.example.springboot_admin.service.IUsersService;
import com.example.springboot_admin.util.JwtUtils;
import com.example.springboot_admin.util.RedisUtils;
import com.example.springboot_admin.vo.ResponseMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author svblack
 * @since 2024-09-13
 */
@RestController
@RequestMapping("/posts")
public class PostsController {
    @Autowired
    IPostsService postsService;
    @Autowired
    RedisUtils redisUtils;
    
    @RequestMapping("/page")
    IPage<Posts> page(@RequestParam(defaultValue = "1") int page,
                      @RequestParam(defaultValue = "5") int limit,
                      @RequestParam(required = false) String query){
        IPage<Posts> pagelist=postsService.page(
                new Page<>(page, limit), new QueryWrapper<Posts>()
                .like(query != null && !query.isEmpty(), "title", query)
                .or()
                .like(query != null && !query.isEmpty(), "content", query));
        return pagelist;
    }

    @RequestMapping("/del")
    Integer del(Integer post_id){
        return postsService.removeById(post_id)?0:1;
    }
    @RequestMapping("delMult")
    Integer delMult(@RequestBody List<Integer> ids){
        System.out.println("ids:"+ids);
        postsService.removeByIds(ids);
        return 0;
    }
}

